package com.service.impl;

import com.domain.Announcement;
import com.entity.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mapper.AnnouncementMapper;
import com.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class AnnouncementServiceImpl implements AnnouncementService {
    @Autowired
    private AnnouncementMapper announcementMapper;


    //显示公告
    @Override
    public PageResult searchAnnouncement(int pageNum, int PageSize) {
        //开启分页查询
        PageHelper.startPage(pageNum,PageSize);
        //调用dao
        Page<Announcement> announcementPage=announcementMapper.searchAnnouncement();
        return new PageResult(announcementPage.getTotal(),announcementPage.getResult());
    }

    //查看详细，用于后面的更新
    @Override
    public Announcement findById(String id) {
        return announcementMapper.findById(id);
    }

    //增加公告
    @Override
    public Integer addannouncement(Announcement announcement) {
        return announcementMapper.addAnnouncement(announcement);
    }

    //删除公告
    @Override
    public boolean delAnnouncement(String id) {
     announcementMapper.delAnnouncement(id);
        return false;
    }

    //更新公告
    @Override
    public boolean editAnnouncement(Announcement announcement) {
        announcementMapper.editAnnouncement(announcement);
        return false;
    }
}
